Skip to content

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Oct 9, 2025

Overview

This PR implements the autoImportFileExcludePatterns parameter in the Go port of TypeScript, allowing users to exclude specific files or directories from auto-import suggestions. This feature was already declared in the UserPreferences struct but not fully implemented with the necessary gating logic.

Changes

Core Implementation

The implementation adds filtering logic based on glob patterns that follows the TypeScript source code closely:

  • getIsExcludedPatterns(): Converts user-provided glob patterns (e.g., /project/node_modules/**/*) into compiled regular expressions using the existing vfs utilities
  • getIsExcluded(): Creates a filter function that checks if source files match any exclusion pattern
  • getIsFileExcluded(): Public helper function for checking file exclusions, matching the TypeScript API

Integration Points

Updated the module enumeration pipeline to respect exclusion patterns:

  • forEachExternalModuleToImportFrom(): Now accepts useCaseSensitiveFileNames parameter and creates exclusion patterns from user preferences
  • forEachExternalModule(): Filters source files and ambient module declarations based on exclusion patterns
  • autoimportsexportinfo.go: Updated call sites to pass the case-sensitive file names flag from the language service host

Usage Example

preferences := &ls.UserPreferences{
    IncludeCompletionsForModuleExports:    core.TSTrue,
    IncludeCompletionsForImportStatements: core.TSTrue,
    AutoImportFileExcludePatterns:         []string{
        "/project/tests/**/*",
        "/project/node_modules/**/*",
    },
}

With these preferences, auto-import suggestions will exclude any files matching the specified patterns, keeping the completion list focused on relevant project files.

Testing

Added comprehensive test coverage in autoImportFileExcludePatterns_test.go:

  • Verifies single exclusion pattern filtering
  • Tests multiple exclusion patterns simultaneously
  • Confirms excluded files don't appear in completions while non-excluded files do

All existing tests continue to pass, confirming backward compatibility.

Bug Fix

Also fixed an unrelated import cycle issue in findallreferences.go that was preventing compilation.

Original prompt

Can you implement another parameter in UserPreferences in types.go; autoImportFileExcludePatterns? Implement the parameter as well as everywhere it needs to be used for gating. This parameter is being ported from submodules/Typescript, so please follow the previous logic closely.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@Copilot Copilot AI changed the title [WIP] Add autoImportFileExcludePatterns to UserPreferences Implement autoImportFileExcludePatterns parameter for filtering auto-import suggestions Oct 9, 2025
@Copilot Copilot AI requested a review from johnfav03 October 9, 2025 16:42
Copilot finished work on behalf of johnfav03 October 9, 2025 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants